package club.justwill.single.assembler;

import club.justwill.single.bean.ProjectSupportResp;
import club.justwill.single.bean.SupportUserResp;
import club.justwill.single.persistence.document.ProjectSupport;
import club.justwill.single.persistence.document.SupportUser;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by luoyu on 1/19/16.
 */
@Component
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class ProjectSupportAssemble {
    public ProjectSupportResp assembleProjectSupport(ProjectSupport projectSupport) {
        ProjectSupportResp projectSupportResp = new ProjectSupportResp();
        projectSupportResp.setProjectId(projectSupport.getProjectId()+"");
        projectSupportResp.setGetFinancing(projectSupport.getGetFinancing()+"");
        projectSupportResp.setPeopleNum(projectSupport.getPeopleNum()+"");
        List<SupportUserResp> supportUserRespList = new ArrayList<SupportUserResp>();

        for(SupportUser supportUser : projectSupport.getSupportUserList()) {
            SupportUserResp supportUserResp = new SupportUserResp();
            supportUserResp.setNickName(supportUser.getNickName()+"");
            supportUserResp.setNum(supportUser.getNum()+"");
            supportUserResp.setPrice(supportUser.getPrice()+"");
            supportUserResp.setDate(supportUser.getDate().getTime()+"");
            supportUserResp.setHeadIcon(supportUser.getHeadIcon()+"");
            supportUserRespList.add(supportUserResp);
        }
        projectSupportResp.setSupportUserRespList(supportUserRespList);
        return projectSupportResp;
    }

}
